?><?
function get_file_icon($file,$size){
  $ext=ExtractFileExt($file);

  switch(lowerstr($ext)){
    case ".txt" :{return "grape/filetypes/".$size."_txt.gif";}
    case ".xls" :{return "grape/filetypes/".$size."_xls.gif";}
    case ".rtf" :{return "grape/filetypes/".$size."_doc.gif";}
    case ".doc" :{return "grape/filetypes/".$size."_doc.gif";}
    case ".inf" :{return "grape/filetypes/".$size."_inf.gif";}
    default     :{return "grape/filetypes/".$size."_default.gif";}

  }
  
}


function insert_down($id,$path,$name){
  ob_start();
  global $defined_file_types;
  
  $type=substr(ExtractFileExt($path),1);
  if(array_search($type,$defined_file_types)===false)$type="def";
  ?><div class="file_download file_icon_<?=$type?>"><?
    ?><div class="file_download_description"><?=$name?></div><?
    ?><div class="file_download_link"><a href="/<?=$path?>"><?=ExtractFileName($path)?></a></div><?
    ?><div class="file_download_size">(<?=size_finer($path)?>)</div><?
  ?></div><?
  $result=ob_get_contents();
  ob_end_clean();
  return $result;
}


function insert_popup($id,$path,$name,$preview){
  ob_start();
  if(file_exists($path)&&is_image($path)){
    if(file_exists($preview)&&is_image($preview)){
      $preview_file=$preview;
    }else{
      $sizes=explode("x",lowerstr($preview));
      if(count($sizes)<2||(int)$sizes[0]==0||(int)$sizes[1]==0){
        em("Bad preview parameter");
      }else{
        $preview_file=get_image_res($path,$sizes[0],$sizes[1]);
      }    
    }
    $full_sizes=get_image_sizes($path);
    ?><a class="popup_image" href="/<?=$path?>" onClick="return popup('/object.image_popup?image=/<?=$path?>',<?=$full_sizes[0]+21?>,<?=$full_sizes[1]+2?>);" target="_blank"><img src="/<?=$preview_file?>" /></a><?
  }else{
    em("Bad image file");
  }
  $result=ob_get_contents();
  ob_end_clean();
  return $result;
}
